from matplotlib import pyplot as plt

plt.subplot(121)
plt.title("训练集和验证集的准确率")
plt.xlabel("训练轮数")
plt.ylabel("准确率")

plt.subplot(122)
plt.title("训练集和验证集的损失值")
plt.xlabel("训练轮数")
plt.ylabel("损失值")

with open("epoch.txt", "r") as epoch_file:
    line = epoch_file.readline()
    index = 1
    loss, acc, pre_val_loss, pre_val_acc = [float(v) for v in line.split()]

    plt.subplot(121)
    plt.scatter(index, acc, marker="o", c="c")
    plt.subplot(122)
    plt.scatter(index, loss, marker="o", c="b")

    for line in epoch_file:
        split = line.split()
        if len(split) == 0:
            break
        loss, acc, val_loss, val_acc = [float(v) for v in split]

        next_index = index + 1
        plt.subplot(121)
        plt.scatter(next_index, acc, marker="o", c="c")
        plt.subplot(122)
        plt.scatter(next_index, loss, marker="o", c="b")

        plt.subplot(121)
        plt.plot([index, next_index], [pre_val_acc, val_acc], color="r")
        plt.subplot(122)
        plt.plot([index, next_index], [pre_val_loss, val_loss], color="r")

        index = next_index
        pre_val_loss = val_loss
        pre_val_acc = val_acc

# plt.subplots_adjust(wspace=0.3)

plt.rcParams['font.sans-serif'] = ['SimHei']
plt.rcParams['axes.unicode_minus'] = False
plt.show()

